package cn.laixueit.controller;

import cn.laixueit.service.GenerateHtml;
import cn.laixueit.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/item")
public class GoodsController {


    @Autowired
    private GoodsService goodsService;
    @Autowired
    private GenerateHtml generateHtml;

    @GetMapping("/{id}.html")
    public String toItemHtml(@PathVariable("id")Long spuId, Model model){
        Map<String,Object> map =  goodsService.loadData(spuId);
        model.addAllAttributes(map);

        generateHtml.genItemHtml(spuId);
        return "item";
    }
}
